package org.gitos.cloud.cmd.controller;

import java.util.List;
import java.util.Map;

import org.gitos.cloud.domain.annotation.UnAuth;
import org.gitos.cloud.domain.comm.Constant;
import org.gitos.cloud.domain.rpc.LedRPC;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.alibaba.dubbo.config.annotation.Reference;
import com.google.common.collect.Maps;

import javax.servlet.http.HttpServletRequest;

/**
 * Created by shizhengchu on 15/12/23.
 */
@RestController
public class CometController extends BaseController {
    private static final Logger log = LoggerFactory
            .getLogger(CometController.class);

    @Reference
    LedRPC ledRPC;

    @RequestMapping("/comet/active")
    public Map<String, Object> active(HttpServletRequest request) {
        Map<String, Object> ret = Maps.newHashMap();
        List<String> activeList;
        try {
            activeList = ledRPC.listActiveComet();
            ret.put(Constant.RET_STATE, 200);
            ret.put(Constant.RET_DATA, activeList);
        } catch (Exception e) {
            log.error(e.getMessage(), e);
            ret.put(Constant.RET_STATE, 500);
            ret.put(Constant.RET_MSG, e.getMessage());
        }
        return ret;
    }

    @RequestMapping("/comet/list")
    public Map<String, Object> listDevice(HttpServletRequest request) {
        return success(ledRPC.listDevice());
    }

}
